package com.nageoffer.shortLink.project.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nageoffer.shortLink.project.dao.entity.ShortLinkDO;
import com.nageoffer.shortLink.project.dto.req.ShortLinkPageReqDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

public interface ShortLinkMapper extends BaseMapper<ShortLinkDO>{


    @Update("<update id=\"incrementStats\">\n" +
            "        UPDATE t_link\n" +
            "        SET total_pv  = total_pv + #{totalPv},\n" +
            "            total_uv  = total_uv + #{totalUv},\n" +
            "            total_uip = total_uip + #{totalUip}\n" +
            "        WHERE gid = #{gid}\n" +
            "          AND full_short_url = #{fullShortUrl}\n" +
            "    </update>")
    void incrementStats(@Param("gid") String gid,
                        @Param("fullShortUrl") String fullShortUrl,
                        @Param("totalPv") Integer totalPv,
                        @Param("totalUv") Integer totalUv,
                        @Param("totalUip") Integer totalUip);

    /**
     * 分页统计短链接
     */
    IPage<ShortLinkDO> pageLink(ShortLinkPageReqDTO requestParam);



}
